﻿package mortal.game.view.skill
{
    import Framework.MQ.*;
    import Message.Command.*;
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.gengine.global.*;
    import extend.language.*;
    import fl.data.*;
    import flash.geom.*;
    import flash.utils.*;
    import mortal.common.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.manager.msgTip.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.rules.*;
    import mortal.game.scene3D.ai.*;
    import mortal.game.scene3D.ai.ais.*;
    import mortal.game.scene3D.ai.data.*;
    import mortal.game.scene3D.layer3D.utils.*;
    import mortal.game.scene3D.map3D.AstarAnyDirection.data.*;
    import mortal.game.scene3D.map3D.util.*;
    import mortal.game.scene3D.player.entity.*;
    import mortal.game.scene3D.util.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.cd.*;
    import mortal.game.view.common.guide.data.*;
    import mortal.game.view.common.guide.navbar.*;
    import mortal.game.view.common.guide.view.*;
    import mortal.game.view.skill.panel.data.*;
    import mortal.game.view.skill.test.*;
    import mortal.game.view.systemSetting.*;
    import mortal.game.view.wizard.*;
    import mortal.game.view.wizard.panel.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class SkillController extends Controller
    {
        private var _module:SkillLearnModule;
        private var _lastCustomPos:int = -1;
        private var _threatModule:SkillThreadModule;
        private var _skillCount:int = 0;
        private var _curIndex:int = -1;
        private var _nextUseSkillTime:int = 0;
        public var _lastUseTime:int = 0;
        private var _autoUseXPTimer:int = -1;
        public static var _skillThenWalkId:int = -1;

        public function SkillController()
        {
            return;
        }// end function

        override protected function initView() : IView
        {
            if (this._module == null)
            {
                this._module = new SkillLearnModule();
            }
            return this._module;
        }// end function

        public function get isModuleShowing() : Boolean
        {
            if (this._module == null)
            {
                return false;
            }
            return !this._module.isHide;
        }// end function

        override protected function initServer() : void
        {
            NetDispatcher.addCmdListener(ServerCommand.SkillAdd, this.updateAllSkillInfos);
            NetDispatcher.addCmdListener(ServerCommand.SkillUpgrade, this.updateAllSkillInfos);
            NetDispatcher.addCmdListener(ServerCommand.ExpUpdate, this.updateAllSkillInfos);
            NetDispatcher.addCmdListener(ServerCommand.SkillPointUpdate, this.skillPointUpdateHandler);
            NetDispatcher.addCmdListener(ServerCommand.CoinUpdate, this.updateAllSkillInfos);
            NetDispatcher.addCmdListener(ServerCommand.RoleLevelUpdate, this.roleLevelUpdateHandler);
            NetDispatcher.addCmdListener(ServerCommand.BackPackItemAdd, this.updateAllSkillInfos);
            Dispatcher.addEventListener(EventName.NavbarButtonUIRowInited, this.sceneUpdateHandler);
            NetDispatcher.addCmdListener(EGateCommand._ECmdGateRune, this.runeGotHandler);
            NetDispatcher.addCmdListener(ServerCommand.BackPackRunePackUpdate, this.runePackChangedHandler);
            NetDispatcher.addCmdListener(ServerCommand.RuneAdd, this.updateRuneUpgradebleHandler);
            NetDispatcher.addCmdListener(ServerCommand.RuneRemove, this.updateRuneUpgradebleHandler);
            NetDispatcher.addCmdListener(ServerCommand.RuneLevelUp, this.updateRuneUpgradebleHandler);
            NetDispatcher.addCmdListener(ServerCommand.RunePowerUpdate, this.updateRuneUpgradebleHandler);
            NetDispatcher.addCmdListener(ServerCommand.RuneDressSuccess, this.dressSuccessHandler);
            Dispatcher.addEventListener(EventName.SkillPanel_ChangedToIndex, this.skillPanelIndexChangeHandler);
            Dispatcher.addEventListener(EventName.SkillShowHideModule, this.showHideHandler);
            Dispatcher.addEventListener(EventName.Skill_SelectPos, this.selectPosHandler);
            Dispatcher.addEventListener(EventName.SkillUpgradeReq, this.skillUpgradeReqHandler);
            Dispatcher.addEventListener(EventName.Skill_RuneUpgrade, this.runeUpgradeHandler);
            Dispatcher.addEventListener(EventName.SkillCheckAndSkillAI, this.checkAndStartSkillAIHandler);
            Dispatcher.addEventListener(EventName.SkillAskServerUseSkill, this.useSkillReqHandler);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicTestBossThreat, this.bossThreatHandler);
            Dispatcher.addEventListener(EventName.SkillPanel_ToSkillBookItem, this.toSkillBookHandler);
            Dispatcher.addEventListener(EventName.ScenePlaySkill, this.skillUseSucessHandler);
            NetDispatcher.addCmdListener(ServerCommand.SkillFailed, this.skillFailedHandler);
            Dispatcher.addEventListener(EventName.SkillCheckAndAddBaiscSkill, this.checkAndAddBasicSkillHandler);
            Dispatcher.addEventListener(EventName.SkillBasicSkillAdd, this.basicSkillAddHandler);
            NetDispatcher.addCmdListener(ServerCommand.WizardSkillUpdate, this.xpSkillChangeHandler);
            NetDispatcher.addCmdListener(ServerCommand.WizardSelectSuccess, this.xpSkillChangeHandler);
            NetDispatcher.addCmdListener(ServerCommand.updateEquipMent, this.roleEquipUpdateHandler);
            return;
        }// end function

        private function runePackChangedHandler(param1:Object = null) : void
        {
            var _loc_3:ItemData = null;
            var _loc_4:* = undefined;
            var _loc_5:int = 0;
            var _loc_6:TRune = null;
            var _loc_7:int = 0;
            cache.skill.clearAllRuneEffect();
            var _loc_2:* = cache.pack.runeBag.allItems;
            if (_loc_2 == null)
            {
                return;
            }
            for each (_loc_3 in _loc_2)
            {
                
                if (_loc_3 == null || _loc_3.extInfo == null || _loc_3.extInfo.extObj == null)
                {
                    continue;
                }
                param1 = _loc_3.extInfo.extObj;
                for (_loc_4 in param1)
                {
                    
                    if (!(_loc_4 is String) || (_loc_4 as String).indexOf("ru_") != 0)
                    {
                        continue;
                    }
                    _loc_5 = parseInt((_loc_4 as String).substr(3));
                    _loc_6 = SkillConfig.instance.getRune(_loc_5);
                    if (_loc_6 == null)
                    {
                        MsgManager.showRollTipsMsg(Language.getStringByParam(21084, _loc_5));
                        continue;
                    }
                    _loc_7 = param1[_loc_4];
                    cache.skill.addRune(_loc_5, _loc_7);
                }
            }
            return;
        }// end function

        private function roleEquipUpdateHandler(param1) : void
        {
            if (this._module != null && !this._module.isHide)
            {
                this.updateSkillInfos();
            }
            Global.instance.addEnterFrame(this.checkAndAutoLearnEquipSkill);
            return;
        }// end function

        private function xpSkillChangeHandler(param1) : void
        {
            cache.skill.updateToNewXPSkill();
            return;
        }// end function

        private function checkAndAddBasicSkillHandler(event:DataEvent) : void
        {
            cache.skill.checkAndAddBasicSkills();
            return;
        }// end function

        private function basicSkillAddHandler(event:DataEvent) : void
        {
            if (this._module != null && !this._module.isHide)
            {
                if (this._module.curIndex == SkillLearnModule.Index_Basic)
                {
                    this.updateSkillInfos();
                }
            }
            return;
        }// end function

        private function checkAndAutoLearnEquipSkill() : void
        {
            var _loc_4:SkillInfo = null;
            Global.instance.removeEnterFrame(this.checkAndAutoLearnEquipSkill);
            if (!AutoGuideNewSkill.instance.isHide)
            {
                return;
            }
            var _loc_1:* = cache.role.roleInfo.level;
            var _loc_2:* = cache.skill.getAllEquipSkills();
            var _loc_3:int = 0;
            for each (_loc_4 in _loc_2)
            {
                
                if (_loc_4.learned)
                {
                    _loc_4 = null;
                    continue;
                }
                if (_loc_4.levelLimited <= _loc_1 && _loc_4.learnable())
                {
                    break;
                }
                _loc_4 = null;
            }
            if (_loc_4 == null)
            {
                return;
            }
            AutoGuideNewSkill.instance.show();
            AutoGuideNewSkill.instance.skillInfo = _loc_4;
            return;
        }// end function

        private function checkAndAutoLearnCareerSkill() : void
        {
            var _loc_5:SkillInfo = null;
            if (!AutoGuideNewSkill.instance.isHide)
            {
                return;
            }
            var _loc_1:* = cache.role.roleInfo.level;
            var _loc_2:* = cache.skill.getAllCareerSkills();
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            while (_loc_4 < _loc_2.length)
            {
                
                _loc_5 = _loc_2[_loc_4];
                if (_loc_5.learned)
                {
                    _loc_5 = null;
                }
                else
                {
                    if (_loc_5.levelLimited <= _loc_1 && _loc_5.learnable())
                    {
                        break;
                    }
                    _loc_5 = null;
                }
                _loc_4++;
            }
            if (_loc_5 == null)
            {
                if (cache.skill.getSkill(GameConst.JPSkillId) == null && _loc_1 >= GameDefConfig.instance.getSystemOpenLevel(26))
                {
                    _loc_3 = GameConst.JPSkillId;
                }
                if (cache.skill.getSkill(GameConst.RollingSkillId) == null && _loc_1 >= GameDefConfig.instance.getSystemOpenLevel(25))
                {
                    _loc_3 = GameConst.RollingSkillId;
                }
                if (cache.skill.getSkill(GameConst.SkillThing) == null && _loc_1 >= GameDefConfig.instance.getSystemOpenLevel(27))
                {
                    _loc_3 = GameConst.SkillThing;
                }
                if (_loc_3 != 0)
                {
                    _loc_5 = new SkillInfo();
                    _loc_5.tSkill = SkillConfig.instance.getInfoById(_loc_3);
                }
            }
            if (_loc_5 == null)
            {
                return;
            }
            AutoGuideNewSkill.instance.show();
            AutoGuideNewSkill.instance.skillInfo = _loc_5;
            return;
        }// end function

        private function skillFailedHandler(param1:Object) : void
        {
            Cache.instance.skill.setWaittingForServer(int(param1), false);
            return;
        }// end function

        private function skillUseSucessHandler(event:DataEvent) : void
        {
            var _loc_2:* = int(event.data);
            var _loc_3:* = SkillConfig.instance.getFirstComboSkill(_loc_2);
            if (_loc_3 != null)
            {
                Cache.instance.skill.setWaittingForServer(_loc_3.skillId, false);
            }
            else
            {
                Cache.instance.skill.setWaittingForServer(_loc_2, false);
            }
            return;
        }// end function

        private function toSkillBookHandler(event:DataEvent) : void
        {
            var _loc_6:SkillInfo = null;
            var _loc_7:TSkill = null;
            var _loc_2:* = event.data as ItemData;
            var _loc_3:* = cache.skill.getAllCareerSkills();
            this._module.showSkillCareerPanel(cache.skill.getAllCareerSkills());
            var _loc_4:int = -1;
            var _loc_5:int = 0;
            while (_loc_5 < _loc_3.length)
            {
                
                _loc_6 = _loc_3[_loc_5];
                if (_loc_6.tSkill.needSkillBook == _loc_2.itemInfo.code || _loc_6.tSkill.needSkillBook == _loc_2.itemInfo.codeUnbind)
                {
                    _loc_4 = _loc_5;
                    break;
                }
                _loc_5++;
            }
            if (_loc_4 >= 0)
            {
                this._curIndex = SkillLearnModule.Index_Career;
                this.updateSkillInfos();
                this._module.selectIndex(_loc_4);
            }
            else
            {
                _loc_3 = cache.skill.getAllEquipSkills();
                for each (_loc_6 in _loc_3)
                {
                    
                    _loc_7 = _loc_6.nextSkill;
                    if (_loc_7 != null && (_loc_7.needSkillBook == _loc_2.itemInfo.code || _loc_7.needSkillBook == _loc_2.itemInfo.codeUnbind))
                    {
                        _loc_4 = _loc_5;
                        break;
                    }
                }
                if (_loc_4 < 0)
                {
                    MsgManager.showRollTipsMsg(Language.getString(21085));
                    return;
                }
                this._curIndex = SkillLearnModule.Index_Equip;
                this.updateSkillInfos();
                this._module.selectIndex(_loc_4);
            }
            return;
        }// end function

        private function selectPosHandler(event:DataEvent) : void
        {
            this._lastCustomPos = int(event.data);
            if (this._module && !this._module.isHide)
            {
                this._curIndex = 0;
                this.updateSkillInfos();
                this._module.selectIndex((this._lastCustomPos - 1));
            }
            return;
        }// end function

        private function showHideHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data as Boolean;
            if (_loc_2)
            {
                view.show();
            }
            else if (this._module != null && !this._module.isHide)
            {
                this._module.hide();
            }
            return;
        }// end function

        private function runeUpgradeHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data as RuneItemData;
            if (_loc_2 == null)
            {
                return;
            }
            var _loc_3:* = Cache.instance.skill.isDebugLearn;
            if (!_loc_2.actived)
            {
                GameProxy.role.activeRune(_loc_2.info.runeId, _loc_3);
            }
            else
            {
                GameProxy.role.upgradeRune(_loc_2.info.runeId, _loc_3);
            }
            return;
        }// end function

        private function updateRuneUpgradebleHandler(param1:Object) : void
        {
            this.updateAllSkillInfos();
            return;
        }// end function

        private function dressSuccessHandler(param1:Object = null) : void
        {
            if (this._module != null && !this._module.isHide)
            {
                this.updateSkillInfos();
            }
            return;
        }// end function

        private function runeGotHandler(param1:MessageBlock) : void
        {
            var _loc_2:* = param1.messageBase as SPublicSeqInt;
            cache.skill.initRuneList(_loc_2.publicSeqInt);
            NetDispatcher.dispatchCmd(ServerCommand.RuneList, null);
            Dispatcher.dispatchEvent(new DataEvent(EventName.BestSkillUpdate));
            return;
        }// end function

        private function bossThreatHandler(param1:MessageBlock) : void
        {
            var _loc_5:SThreat = null;
            var _loc_6:int = 0;
            var _loc_7:SkillThreatData = null;
            var _loc_2:* = param1.messageBase as SBossThreatList;
            var _loc_3:* = new DataProvider();
            var _loc_4:* = new Dictionary();
            for each (_loc_5 in _loc_2.topThreats)
            {
                
                _loc_4[_loc_5.name] = 1;
            }
            for each (_loc_5 in _loc_2.lowestThreats)
            {
                
                _loc_4[_loc_5.name] = 2;
            }
            _loc_6 = 0;
            while (_loc_6 < _loc_2.threatList.length)
            {
                
                _loc_5 = _loc_2.threatList[_loc_6];
                _loc_7 = new SkillThreatData();
                _loc_7.data = _loc_5;
                _loc_7.index = _loc_6 + 1;
                if (_loc_4[_loc_5.name] == 1)
                {
                    _loc_7.isHight = true;
                }
                else if (_loc_4[_loc_5.name] == 2)
                {
                    _loc_7.isLow = true;
                }
                _loc_3.addItem(_loc_7);
                _loc_6++;
            }
            if (this._threatModule && !this._threatModule.isHide)
            {
                this._threatModule.updateList(_loc_3);
            }
            return;
        }// end function

        public function get threatModule() : SkillThreadModule
        {
            if (this._threatModule == null)
            {
                this._threatModule = new SkillThreadModule();
            }
            return this._threatModule;
        }// end function

        private function sceneUpdateHandler(event:DataEvent) : void
        {
            Dispatcher.removeEventListener(EventName.NavbarButtonUIRowInited, this.sceneUpdateHandler);
            this.updateAllSkillInfos();
            if (PulseSharedObject.getValue(SkillCache.Skill_IconRedPointTime) != null)
            {
                cache.skill.lastIconRedPointTime = Number(PulseSharedObject.getValue(SkillCache.Skill_IconRedPointTime));
            }
            if (PulseSharedObject.getValue(SkillCache.Skill_ModuleRedPointTime) != null)
            {
                cache.skill.lastModuleRedPointTime = Number(PulseSharedObject.getValue(SkillCache.Skill_ModuleRedPointTime));
            }
            this.runePackChangedHandler(null);
            return;
        }// end function

        private function skillPointUpdateHandler(param1:Object = null) : void
        {
            if (this._module != null && !this._module.isHide)
            {
                this._module.updateHaveSkillPoint(cache.login.loginGame.money.skillPoint);
            }
            this.updateAllSkillInfos();
            return;
        }// end function

        private function roleLevelUpdateHandler(param1 = null) : void
        {
            this.checkAndAutoLearnCareerSkill();
            this.updateAllSkillInfos();
            return;
        }// end function

        private function updateAllSkillInfos(param1:Object = null) : void
        {
            var _loc_4:Number = NaN;
            var _loc_5:int = 0;
            var _loc_2:* = cache.role.roleInfo.level;
            if (_loc_2 < 40)
            {
                this.checkAndAddBasicSkillHandler(null);
            }
            if (this._module != null && !this._module.isHide)
            {
                this.updateSkillInfos();
            }
            var _loc_3:* = cache.skill.getLearnableOrUpgradableCount();
            if (_loc_3 > 0)
            {
                _loc_4 = ClockManager.instance.nowDate.time;
                if (cache.skill.lastIconRedPointTime == -1 || _loc_4 - cache.skill.lastIconRedPointTime >= SkillCache.RedPointRefreshTime)
                {
                    cache.skill.lastIconRedPointTime = _loc_4;
                    NavbarButtonUIRow.instance.showHideFilter(ModuleType.Skills);
                }
                if (this._skillCount != _loc_3)
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.BestSkillUpdate));
                }
                this._skillCount = _loc_3;
                _loc_5 = GameDefConfig.instance.getSystemOpenLevel(62);
                if (GameController.autoGuide.hasShowModule(ModuleType.Skills) && cache.role.roleInfo.level < _loc_5)
                {
                    if (SkillHintIcon.instance.isHide)
                    {
                        SkillHintIcon.instance.show();
                    }
                }
                else if (cache.role.roleInfo.level >= _loc_5)
                {
                    if (SkillHintIcon.getMyInstance() != null)
                    {
                        if (!SkillHintIcon.instance.isHide)
                        {
                            SkillHintIcon.instance.hide();
                        }
                    }
                }
            }
            else
            {
                NavbarButtonUIRow.instance.setLightEffect(ModuleType.Skills, false);
                NavbarButtonUIRow.instance.showHideFilter(ModuleType.Skills, false);
                if (SkillHintIcon.getMyInstance() != null)
                {
                    if (!SkillHintIcon.instance.isHide)
                    {
                        SkillHintIcon.instance.hide();
                    }
                }
            }
            return;
        }// end function

        private function skillPanelIndexChangeHandler(event:DataEvent) : void
        {
            if (this._module == null || this._module.isHide)
            {
                return;
            }
            this._curIndex = int(event.data);
            this.updateSkillInfos();
            return;
        }// end function

        private function skillUpgradeReqHandler(event:DataEvent) : void
        {
            var _loc_2:* = int(event.data);
            if (_loc_2 == 0)
            {
                return;
            }
            var _loc_3:* = cache.skill.getSkill(_loc_2);
            var _loc_4:* = Cache.instance.skill.isDebugLearn;
            if (_loc_3 == null)
            {
                GameProxy.role.learnSkill(_loc_2, _loc_4);
                return;
            }
            GameProxy.role.upgradeSkill(_loc_2, _loc_4);
            return;
        }// end function

        public function checkAndStartSkillAIHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data as SkillInfo;
            this.checkAndStartAIBySkill(_loc_2, true);
            return;
        }// end function

        public function checkAndStartAIBySkill(param1:SkillInfo, param2:Boolean = false) : Boolean
        {
            var _loc_3:int = 0;
            var _loc_6:Point = null;
            var _loc_7:Point = null;
            var _loc_8:int = 0;
            var _loc_9:IEntity = null;
            var _loc_10:Point = null;
            if (param1 == null)
            {
                return false;
            }
            if (cache.skill.needDisableUseSkill)
            {
                return false;
            }
            if (RolePlayer.instance.isInSpasticity)
            {
                return false;
            }
            if (GameMapUtil.isCanNotPlayerSkillMap())
            {
                return false;
            }
            if (RolePlayer.instance.isJumping)
            {
                return false;
            }
            if (param1.tSkill.skillId == GameConst.SkillMount)
            {
                GameManager.instance.popupModuleType(ModuleType.DownUpMounts);
                return true;
            }
            if (param1.tSkill.skillId == GameConst.SkillThing)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.AskSingleZazen));
                return true;
            }
            if (param1.tSkill.skillId == GameConst.JPSkillId)
            {
                if (!BuffUtil.isCanRoleWalk())
                {
                    if (param2)
                    {
                        MsgManager.showRollTipsMsg(Language.getString(21086));
                    }
                    return false;
                }
                GameManager.instance.popupModuleType(ModuleType.RUN);
                return true;
            }
            if (param1.tSkill.skillId == GameConst.RollingSkillId)
            {
                if (!BuffUtil.isCanRoleFireSkill(param1))
                {
                    if (param2)
                    {
                        MsgManager.showRollTipsMsg(Language.getString(21087));
                    }
                    return false;
                }
                GameManager.instance.popupModuleType(ModuleType.SPACE);
                return true;
            }
            param1 = cache.skill.getSkillBySerialId(param1.tSkill.series);
            if (param1 == null)
            {
                return false;
            }
            if (GameMapUtil.curMapState.isPetBreakMap)
            {
                if (SkillUtil.isBeidongSkill(param1.tSkill.skillId))
                {
                    MsgManager.showRollTipsMsg(Language.getString(21088));
                    return false;
                }
                _loc_3 = cache.copy.petBreakCopy.entityInfo.mana;
            }
            else
            {
                _loc_3 = cache.role.roleInfo.mana;
            }
            if (param1.tSkill.consume > _loc_3)
            {
                if (param2)
                {
                    MsgManager.showRollTipsMsg(Language.getString(21089));
                }
                return false;
            }
            if (SkillUtil.isNoSpasticitySkill(param1) && !GameMapUtil.isCanNotPlayerSkillMap())
            {
                GameProxy.sceneProxy.fight([], param1.skillId);
                return true;
            }
            var _loc_4:* = ThingUtil.selectEntity as MonsterPlayer;
            if (_loc_4 != null && BossRule.isCollectBoss(_loc_4))
            {
                ThingUtil.selectEntity = null;
            }
            var _loc_5:* = AIFactory.instance.outFollowFightAIData();
            _loc_5.skillInfo = param1;
            FightUtil.selectEntityBySkill(_loc_5, cache.shortcut.isLastKeyByClick);
            if (!SkillUtil.canMapUseSkill(param1, _loc_5))
            {
                return false;
            }
            if (_loc_5.target == null && _loc_5.point == null)
            {
                MsgManager.showFightTipsImpl(Language.getString(20054), MsgRollTipsType.msgRollTips6, true);
                AIFactory.instance.inFollowFightAIData(_loc_5);
                return false;
            }
            if (_loc_5.isSkillThenWalk)
            {
                AIManager.cancelAll();
                _loc_6 = new Point(_loc_5.point.x, _loc_5.point.y);
                _loc_7 = GeomUtil.getPointByDistance(RolePlayer.instance.x2d, RolePlayer.instance.y2d, _loc_5.point.x, _loc_5.point.y, _loc_5.range - 20);
                _loc_5.point.x = _loc_7.x;
                _loc_5.point.y = _loc_7.y;
                _loc_8 = GeomUtil.calcDistance(RolePlayer.instance.x2d, RolePlayer.instance.y2d, _loc_6.x, _loc_6.y);
                AIManager.addFightOnce(_loc_5);
                if (_loc_8 > param1.distance)
                {
                    clearSkillThenWallTimer();
                    AIManager.addCallback(skillThenWalkCallback, [_loc_6, 50, param1.tSkill.skillId]);
                }
                AIManager.start();
                return true;
            }
            else if (_loc_5.target != null)
            {
                _loc_9 = _loc_5.target as IEntity;
                if (_loc_5.target is MonsterPlayer && BossRule.isCollectBoss(_loc_5.target as MonsterPlayer))
                {
                    if (_loc_9.entityID == Cache.instance.skill.waittingServerCollectID)
                    {
                        return false;
                    }
                    if (AIManager.curAI != null && AIManager.curAI is CollectAI && AIManager.curAI.data.target == _loc_9)
                    {
                        return false;
                    }
                    AIManager.onAIControl(AIType.Collect, _loc_5.target);
                }
                else
                {
                    if (GameMapUtil.curMapState.isPetBreakMap && _loc_5.meRole is RolePlayer)
                    {
                        _loc_5.meRole = ThingUtil.entityUtil.getSelfPetEntity();
                    }
                    else if (!GameMapUtil.curMapState.isPetBreakMap)
                    {
                        _loc_5.meRole = RolePlayer.instance;
                    }
                    AIManager.onAIControl(AIType.Follow_fight, _loc_5);
                }
                return true;
            }
            else if (_loc_5.point != null)
            {
                AIManager.cancelAll();
                _loc_10 = new Point(_loc_5.point.x, _loc_5.point.y);
                AIManager.addMoveTo(_loc_10, _loc_5.range);
                AIManager.addFollowFight(_loc_5);
                AIManager.start();
                return true;
            }
            return false;
        }// end function

        private function useSkillReqHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data as FollowFightAIData;
            if (_loc_2 == null)
            {
                return;
            }
            var _loc_3:* = _loc_2.skillInfo;
            if (_loc_3 == null)
            {
                return;
            }
            if (!BuffUtil.isCanRoleFireSkill(_loc_3))
            {
                return;
            }
            if (cache.skill.isWaittingForServer(_loc_3.skillId))
            {
                return;
            }
            var _loc_4:* = getTimer();
            var _loc_5:* = cache.cd.getCDData(_loc_3, CDDataType.skillInfo);
            var _loc_6:* = ClientSetting.local.getIsDone(IsDoneType.IsNotCD);
            if (!_loc_6 && _loc_5 && _loc_5.isCoolDown)
            {
                MsgManager.showFightTipsImpl(Language.getStringByParam(20051, Language.getString(20052)), MsgRollTipsType.msgRollTips6, true);
                return;
            }
            this._lastUseTime = _loc_4;
            RolePlayer.instance.stopWalkSendPoint();
            this.resetTargetPointForMouseFont(_loc_2, _loc_3);
            GameProxy.sceneProxy.fight(_loc_2.entitys, _loc_3.skillId, _loc_2.point);
            Cache.instance.skill.setWaittingForServer(_loc_3.skillId);
            if (AutoGuideCache.isWaittingFollowFightAI)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.AI_FightAIEnd, _loc_2));
            }
            if (!WizardController.curMapCanUseXp())
            {
                return;
            }
            if (Cache.instance.wizard.fightWizardData != null && Cache.instance.wizard.fightWizardData.tSprite != null)
            {
                if (AutoFightAI.isWorking && this._autoUseXPTimer < 0 && SkillUtil.isShouldGuideUseXPSkill() && cache.role.roleInfo.anger >= WizardUtil.maxAnger && cache.role.roleInfo.level >= GameConst.AutoUseWizardSkillMinLv && ClientSetting.local.getIsDone(IsDoneType.UseWizardSkill) && Cache.instance.wizard.fightWizardData.tSpriteEx.xpskillId > 0)
                {
                    this._autoUseXPTimer = setTimeout(this.timeCheckAutoUseXP, 5000);
                }
                else if (Cache.instance.wizard.fightWizardData.tSpriteEx.xpskillId == _loc_3.skillId)
                {
                    GameController.guide.guideUseXp(false);
                }
                else if (cache.role.roleInfo.anger >= WizardUtil.maxAnger && Cache.instance.wizard.fightWizardData.tSpriteEx.xpskillId > 0)
                {
                    GameController.guide.guideUseXp(true);
                }
            }
            return;
        }// end function

        public function clearAutoUseXpTimer() : void
        {
            if (this._autoUseXPTimer > 0)
            {
                clearTimeout(this._autoUseXPTimer);
                this._autoUseXPTimer = -1;
            }
            return;
        }// end function

        private function timeCheckAutoUseXP() : void
        {
            this._autoUseXPTimer = -1;
            if (AutoFightAI.isWorking && SkillUtil.isShouldGuideUseXPSkill() && cache.role.roleInfo.anger >= WizardUtil.maxAnger && cache.role.roleInfo.level >= GameConst.AutoUseWizardSkillMinLv && ClientSetting.local.getIsDone(IsDoneType.UseWizardSkill) && Cache.instance.wizard.fightWizardData.tSpriteEx.xpskillId > 0)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.WizardUseXpSkill, Cache.instance.wizard.fightWizardData.tSpriteEx.xpskillId));
            }
            return;
        }// end function

        private function resetTargetPointForMouseFont(param1:FollowFightAIData, param2:SkillInfo) : void
        {
            var _loc_3:Number = NaN;
            var _loc_4:Number = NaN;
            var _loc_5:Number = NaN;
            var _loc_6:Number = NaN;
            var _loc_7:Number = NaN;
            var _loc_8:Number = NaN;
            if (param2.tSkill.targetSelect == ESkillTargetSelect._ESkillTargetSelectMouseFront)
            {
                _loc_3 = RolePlayer.instance.x2d;
                _loc_4 = RolePlayer.instance.y2d;
                _loc_5 = GameConst.JumpCutWeaponDis;
                if (param1.mouseFontEntity != null && param1.mouseFontEntity.entityInfo != null)
                {
                    _loc_7 = param1.mouseFontEntity.x2d;
                    _loc_8 = param1.mouseFontEntity.y2d;
                    _loc_5 = param1.mouseFontEntity.entityInfo.bodySize + GameConst.JumpCutWeaponDis;
                }
                else
                {
                    _loc_7 = param1.point.x;
                    _loc_8 = param1.point.y;
                }
                _loc_6 = GeomUtil.calcDistance(_loc_3, _loc_4, _loc_7, _loc_8) + 1e-005;
                if (_loc_5 >= _loc_6)
                {
                    param1.point.x = _loc_3 + (_loc_7 - _loc_3) * 2 / _loc_6;
                    param1.point.y = _loc_4 + (_loc_8 - _loc_4) * 2 / _loc_6;
                }
                else
                {
                    param1.point.x = _loc_3 + (_loc_7 - _loc_3) * (_loc_6 - _loc_5) / _loc_6;
                    param1.point.y = _loc_4 + (_loc_8 - _loc_4) * (_loc_6 - _loc_5) / _loc_6;
                }
            }
            return;
        }// end function

        private function updateSkillInfos() : void
        {
            if (this._module == null)
            {
                return;
            }
            switch(this._curIndex)
            {
                case SkillLearnModule.Index_Career:
                {
                    this._module.showSkillCareerPanel(cache.skill.getAllCareerSkills(Math.max(75, cache.role.roleInfo.level)));
                    break;
                }
                case SkillLearnModule.Index_Basic:
                {
                    this._module.showSkillBasicPanel(cache.skill.getAllBasicSkills());
                    break;
                }
                case SkillLearnModule.Index_Equip:
                {
                    this._module.showSkillEquipPanel(cache.skill.getAllEquipSkills(cache.role.roleInfo.level + 2));
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public function refreshModuleRedPoint() : void
        {
            if (this._module == null || this._module.isHide)
            {
                return;
            }
            this._module.refreshRedPoint();
            return;
        }// end function

        public function refreshIconRedPoint() : void
        {
            this.updateAllSkillInfos();
            return;
        }// end function

        public static function clearSkillThenWallTimer() : void
        {
            if (_skillThenWalkId > 0)
            {
                clearTimeout(_skillThenWalkId);
                _skillThenWalkId = -1;
            }
            return;
        }// end function

        public static function skillThenWalkCallback(param1:Array) : void
        {
            var _loc_2:* = param1[0] as Point;
            var _loc_3:* = int(param1[1]);
            var _loc_4:* = int(param1[2]);
            param1[1] = _loc_3 - 1;
            if (Cache.instance.skill.isWaittingForServer(_loc_4))
            {
                if (_loc_3 > 0)
                {
                    _skillThenWalkId = setTimeout(skillThenWalkCallback, 20, param1);
                }
                return;
            }
            _skillThenWalkId = -1;
            if (AutoFightAI.isWorking && AIManager.curAI is AutoFightAI)
            {
                AutoFightAI.instance.cancelAll();
                AutoFightAI.instance.addMoveTo(_loc_2, 5);
                AutoFightAI.instance.startAIList();
            }
            else
            {
                AIManager.cancelAll();
                AIManager.addMoveTo(_loc_2, 5);
                AIManager.start();
            }
            return;
        }// end function

    }
}
